class Message
  
  attr_accessor :unid, :sender, :subject, :importance, :received
  
  def parse(entry)
    self.unid = entry['unid']    
    self.importance = entry['entrydata'][1]['number']
    self.sender = entry['entrydata'][2]['text']       
    self.subject = entry['entrydata'][3]['text']
    
    start = entry['entrydata'][4]['datetime']
    str = start.sub!(',','')
    date = DateTime.parse(str)    
    self.received = date.strftime("%a %m/%d/%Y %I:%M %p")  
  end
  
  
  def brief_subject
    return trim_by_words(subject, 4)
  end
  
 
def trim_by_words(string,wordcount)
    string.split[0..(wordcount-1)].join(" ") +(string.split.size > wordcount ? "..." : "")
end

  
end